import pymysql

# 打开数据库连接
conn = pymysql.connect('localhost', 'root', '459gjy217', 'test')
# 使用cursor()方法获取操作游标
cursor = conn.cursor()
# SQL语句：查询
sql = "SELECT * FROM 乔丹数据 WHERE season = '87-88' "
# sql = "SELECT * FROM 乔丹数据 ORDER BY round "  # 排序
# 异常处理
try:
    # 执行SQL语句
    cursor.execute(sql)
    # 获取所有的记录列表
    results = cursor.fetchall()
    # 遍历列表
    for row in results:
        # 打印列表元素
        # print(row)
        name = row[0]
        season = row[1]
        round = row[2]
        result = row[3]
        match = row[4]
        time = row[5]
        shoot = row[6]
        hit = row[7]
        att = row[8]
        tp = row[9]
        hit1 = row[10]
        att1 = row[11]
        ft = row[12]
        hit2 = row[13]
        att2 = row[14]
        rebs = row[15]
        firh = row[16]
        sech = row[17]
        ast = row[18]
        stl = row[19]
        bck = row[20]
        to = row[21]
        fouls = row[22]
        pts = row[23]
        print(name, season, round, result, match, time,
              shoot, hit, att, tp, hit1, att1, ft, hit2,
              att2, rebs, firh, sech, ast, stl, bck,
              to, fouls, pts)
except:
    print('Uable to fetch data!')

finally:
    conn.close()  # 关闭数据库连接
    cursor.close()

